package com.wc.codeforces.DP.线性DP.Alice_s_Adventures_in_Cutting_Cake;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/11/11 12:02
 * @description https://codeforces.com/contest/2028/problem/C
 */
public class Main {
    /**
     * 质量很高
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] a = new int[N];
    // f1[i] 表示 从 1 ~ i能够最多容纳多少人够, f2[i] 表示从 i ~ n最多容纳多少人够 v
    static int[] f1 = new int[N], f2 = new int[N];
    static long[] s = new long[N];
    static int n, m, v;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            v = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            cals();
            Arrays.fill(f1, 1, n + 2, 0);
            Arrays.fill(f2, 1, n + 2, 0);

            work(f1);

            reverse(a);
            cals();
            work(f2);
            reverse(f2);
            reverse(a);
            cals();

            long res = -1;
            for (int i = 1; i <= n; i++) {
                // r = n + 1, 表示有可能不需要后面的
                int l = i, r = n + 1;
                while (l < r) {
                    int mid = l + r + 1 >> 1;
                    if (f1[i - 1] + f2[mid] >= m) l = mid;
                    else r = mid - 1;
                }
                if (f1[i - 1] + f2[r] >= m) res = Math.max(res, s[r - 1] - s[i - 1]);
            }
            out.println(res);
        }
        out.flush();
    }

    static void work(int[] f) {
        for (int i = 1; i <= n; i++) {
            int l = 1, r = n;
            while (l < r) {
                int mid = l + r >> 1;
                if (s[mid] - s[i - 1] >= v) r = mid;
                else l = mid + 1;
            }
            if (s[r] - s[i - 1] >= v) f[r] = Math.max(f[r], f[i - 1] + 1);
        }
        for (int i = 1; i <= n; i++) f[i] = Math.max(f[i], f[i - 1]);
    }

    static void cals() {
        for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
    }

    static void reverse(int[] a) {
        for (int i = 1, j = n; i < j; i++, j--) {
            int tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

